<?php
namespace app\web\dao;

use xto\data\Sql;
use xto\App;
use xto\Util;
use xto\membership\context\Users;

use xto\data\IDao;

class ContentDao extends IDao{
	public function __construct() {
		parent::__construct('web_content','cid'); 
	} 

	public function save($data){
		if(!isset($data['title']) || !isset($data['content'])){
			return false;
		}

		$new_data=[
			'title'=>$data['title'],
			'content'=>$data['content'],
			'keywords'=>isset($data['keywords'])?$data['keywords']:'',
			'description'=>isset($data['description'])?$data['description']:'',
			'appid'=>$this->app->appid,
			'createdate'=>Util::getdate()
		];

		$result=parent::save($new_data);
		if($result){
			if(isset($data['img'])){
				//插入图片 
				ImgDao::instance()->create($this->id,'content',$data['img']);
			}
		}		

		return $result;
	}

	public function update($data){
		if(!isset($data['title']) || !isset($data['content']) || !isset($data['cid'])){
			return false;
		}

		$new_data=[
			'title'=>$data['title'],
			'content'=>$data['content'],
			'keywords'=>isset($data['keywords'])?$data['keywords']:'',
			'description'=>isset($data['description'])?$data['description']:'',
			'appid'=>$this->app->appid,
			'cid'=>$data['cid'],
			'update_time'=>Util::getdate()
		]; 
		return parent::update($new_data);
	}
}